<?php


namespace app\api\controller\v3;


use api\channel\jutuike\FoodUnion;
use api\channel\jutuike\TravelUnion;
use app\BaseController;
use app\middleware\coupon_order\CheckAgentJutuikeChannelPremission;
use app\model\AgentChannel;
use app\model\CouponBrand;
use app\model\CouponCate;
use app\model\CouponProductChannel;
use think\Request;

class Coupon extends BaseController
{

    use \app\api\controller\traits\coupon_order\Coupon;
    //主聚推客

    use \app\api\controller\traits\coupon_order\Jutuike;//聚推客渠道接口整理


    protected $middleware = [
        \app\middleware\ApiChannel::class,
        \app\middleware\ApiUserAuthV2::class => ['except' => ['phoneInfo']],
        \app\middleware\coupon_order\CheckAgentJutuikeChannelPremission::class => ['only' => [ //聚推客
            'getUnionUrl',
            'getFoodJumpUrl',
            'getJumpUrlByTravelId',
            'getJumpUrlByBrandId',//权益
        ]],
    ];

    protected function initialize()
    {

        $supplierChannle = CheckAgentJutuikeChannelPremission::matchChannel();

        $this->request->servType = $supplierChannle ? $supplierChannle->supplierInfo->serv_type : PRODUCT_COUPON_SERV;

        $this->request->servName = '渠道';

        parent::initialize();
    }


    /**
     * 顶部推荐
     */
    public function getTop(Request $request)
    {
        //临时方案
        $rows = [
            [
                'name' => '腾讯',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/qqv.png',
                'brand_id' => '2',
            ],
            [
                'name' => '优酷',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/youku.png',
                'brand_id' => '3',
            ],
            [
                'name' => '爱奇艺',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/iqiyi.png',
                'brand_id' => '1',
            ],
            [
                'name' => '喜马拉雅',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/ximalaya.png',
                'brand_id' => '5',
            ],
            [
                'name' => 'QQ音乐',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/qqyinyue.png',
                'brand_id' => '20',
            ]
        ];
        //add by ymzhang 2022-07-04
        foreach ($rows as $key => $brand) {
            $info = CouponBrand::find($brand['brand_id']);
            $rows[$key]['discount_logo'] = $info->discount_logo;
        }

        $ad_banner = [
            [
                'name' => '饿了么',
                'brand_id' => '7',
            ]
        ];

        $ad_block = [
            [
                'name' => 'QQ音乐',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/qqyinyue.png',
                'brand_id' => '20',
            ],
            [
                'name' => '饿了么',
                'brand_id' => '7',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/ele.png',
            ],
            [
                'name' => '美团',
                'brand_id' => '6',
                'image_url' => 'https://img.jutuike.com/taokeout/mall/icon/meituan.png',
            ]
        ];


        return success('成功！', compact('rows', 'ad_banner', 'ad_block'));
    }
}